package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceBuildConfigDAO;
import com.ourteam.workspace.dao.WorkspaceBuildConfig;
import com.ourteam.workspace.dao.WorkspaceBuildConfigDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:33 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceBuildConfigDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceBuildConfigDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        WorkspaceId,
        BuildConfigName,
        BuildPath,
        SourceCompiler,
        AutoBuildCorn,
        SourceCodePaths,
        DependLibary,
        TargetRuntimeEnv,
        AutoDeploy,
        Status,
        Remarks,
        LastBuildTime,
        ProductionType,
        ProductionName,
        DeployType,
        DeployPath,
        DeployUser,
        DeployPassword,
        SourceEncode
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.WorkspaceId,
        _DataObjectProperty.BuildConfigName,
        _DataObjectProperty.BuildPath,
        _DataObjectProperty.SourceCompiler,
        _DataObjectProperty.AutoBuildCorn,
        _DataObjectProperty.SourceCodePaths,
        _DataObjectProperty.DependLibary,
        _DataObjectProperty.TargetRuntimeEnv,
        _DataObjectProperty.AutoDeploy,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.LastBuildTime,
        _DataObjectProperty.ProductionType,
        _DataObjectProperty.ProductionName,
        _DataObjectProperty.DeployType,
        _DataObjectProperty.DeployPath,
        _DataObjectProperty.DeployUser,
        _DataObjectProperty.DeployPassword,
        _DataObjectProperty.SourceEncode
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<WorkspaceBuildConfig, WorkspaceBuildConfigDAOQueryBean> daoHelper;

  public AbstractWorkspaceBuildConfigDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<WorkspaceBuildConfig, WorkspaceBuildConfigDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceBuildConfig
   * @throws Exception
   */
  public boolean checkIsUnique(WorkspaceBuildConfig aWorkspaceBuildConfig) throws Exception {

    if (aWorkspaceBuildConfig == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceBuildConfig.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceBuildConfig
   * @throws Exception
   */
  public void insert(WorkspaceBuildConfig aWorkspaceBuildConfig) throws Exception {

    super.doInsert(aWorkspaceBuildConfig);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceBuildConfig
   * @throws Exception
   */
  public void batchInsert(WorkspaceBuildConfig[] aWorkspaceBuildConfigs) throws Exception {

    super.doBatchInsert(aWorkspaceBuildConfigs);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceBuildConfigDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceBuildConfig aWorkspaceBuildConfig) throws Exception {

    delete(aWorkspaceBuildConfig.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceBuildConfig
   * @throws Exception
   */
  public void update(WorkspaceBuildConfig aWorkspaceBuildConfig) throws Exception {

    if (aWorkspaceBuildConfig.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceBuildConfig);

    WorkspaceBuildConfig tempObj = findById(aWorkspaceBuildConfig.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceBuildConfig, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceBuildConfigs[]
   * @throws Exception
   */
  public void batchUpdate(WorkspaceBuildConfig[] aWorkspaceBuildConfigs) throws Exception {

    super.doBatchUpdate(aWorkspaceBuildConfigs);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceBuildConfig
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      WorkspaceBuildConfig aWorkspaceBuildConfig, WorkspaceBuildConfigDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceBuildConfig, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceBuildConfigDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(WorkspaceBuildConfig aWorkspaceBuildConfig) throws Exception {

    if (aWorkspaceBuildConfig.getProductionType() == null) {
      throw new Exception("The WorkspaceBuildConfig.productionType value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getProductionName() == null) {
      throw new Exception("The WorkspaceBuildConfig.productionName value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getDeployType() == null) {
      throw new Exception("The WorkspaceBuildConfig.deployType value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getDeployPath() == null) {
      throw new Exception("The WorkspaceBuildConfig.deployPath value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getDeployUser() == null) {
      throw new Exception("The WorkspaceBuildConfig.deployUser value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getDeployPassword() == null) {
      throw new Exception("The WorkspaceBuildConfig.deployPassword value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getSourceEncode() == null) {
      throw new Exception("The WorkspaceBuildConfig.sourceEncode value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getBuildConfigName() == null) {
      throw new Exception("The WorkspaceBuildConfig.buildConfigName value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getBuildPath() == null) {
      throw new Exception("The WorkspaceBuildConfig.buildPath value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getSourceCompiler() == null) {
      throw new Exception("The WorkspaceBuildConfig.sourceCompiler value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getAutoBuildCorn() == null) {
      throw new Exception("The WorkspaceBuildConfig.autoBuildCorn value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getSourceCodePaths() == null) {
      throw new Exception("The WorkspaceBuildConfig.sourceCodePaths value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getDependLibary() == null) {
      throw new Exception("The WorkspaceBuildConfig.dependLibary value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getTargetRuntimeEnv() == null) {
      throw new Exception("The WorkspaceBuildConfig.targetRuntimeEnv value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getAutoDeploy() == null) {
      throw new Exception("The WorkspaceBuildConfig.autoDeploy value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getStatus() == null) {
      throw new Exception("The WorkspaceBuildConfig.status value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getRemarks() == null) {
      throw new Exception("The WorkspaceBuildConfig.remarks value is not allow NULL");
    }

    if (aWorkspaceBuildConfig.getLastBuildTime() == null) {
      throw new Exception("The WorkspaceBuildConfig.lastBuildTime value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceBuildConfig findById(final long id) throws Exception {

    WorkspaceBuildConfigDAOQueryBean queryBean = new WorkspaceBuildConfigDAOQueryBean();

    WorkspaceBuildConfigDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceBuildConfig[] WorkspaceBuildConfigs = query(queryBean);

    if (WorkspaceBuildConfigs.length == 0) {
      return null;
    } else {
      return WorkspaceBuildConfigs[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceBuildConfig[]
   * @throws Exception
   */
  public WorkspaceBuildConfig[] query(WorkspaceBuildConfigDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcWorkspaceBuildConfigRowMapper());

    return (WorkspaceBuildConfig[]) result.toArray(new WorkspaceBuildConfig[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(WorkspaceBuildConfigDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceBuildConfigDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceBuildConfig[] aWorkspaceBuildConfigs, WorkspaceBuildConfigDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aWorkspaceBuildConfigs, queryBean);
  }

  public void synchronize(
      WorkspaceBuildConfig[] aWorkspaceBuildConfigs,
      WorkspaceBuildConfigDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceBuildConfig> callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceBuildConfigs, queryBean, callBack);
  }

  public static class JdbcWorkspaceBuildConfigRowMapper implements RowMapper<WorkspaceBuildConfig> {

    public WorkspaceBuildConfig mapRow(ResultSet resultSet, int arg1) throws SQLException {
      WorkspaceBuildConfig object = new WorkspaceBuildConfig();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object workspaceId = null;

        workspaceId = resultSet.getObject(columnIndex++);

        object.setWorkspaceIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceId, workspaceId);
        }

        Object buildConfigName = null;

        buildConfigName = resultSet.getObject(columnIndex++);

        object.setBuildConfigNameNull(resultSet.getBoolean(columnIndex++));

        if (buildConfigName != null) {

          setBeanValue(object, _DataObjectProperty.BuildConfigName, buildConfigName);
        }

        Object buildPath = null;

        buildPath = resultSet.getObject(columnIndex++);

        object.setBuildPathNull(resultSet.getBoolean(columnIndex++));

        if (buildPath != null) {

          setBeanValue(object, _DataObjectProperty.BuildPath, buildPath);
        }

        Object sourceCompiler = null;

        sourceCompiler = resultSet.getObject(columnIndex++);

        object.setSourceCompilerNull(resultSet.getBoolean(columnIndex++));

        if (sourceCompiler != null) {

          setBeanValue(object, _DataObjectProperty.SourceCompiler, sourceCompiler);
        }

        Object autoBuildCorn = null;

        autoBuildCorn = resultSet.getObject(columnIndex++);

        object.setAutoBuildCornNull(resultSet.getBoolean(columnIndex++));

        if (autoBuildCorn != null) {

          setBeanValue(object, _DataObjectProperty.AutoBuildCorn, autoBuildCorn);
        }

        Object sourceCodePaths = null;

        sourceCodePaths = resultSet.getObject(columnIndex++);

        object.setSourceCodePathsNull(resultSet.getBoolean(columnIndex++));

        if (sourceCodePaths != null) {

          setBeanValue(object, _DataObjectProperty.SourceCodePaths, sourceCodePaths);
        }

        Object dependLibary = null;

        dependLibary = resultSet.getObject(columnIndex++);

        object.setDependLibaryNull(resultSet.getBoolean(columnIndex++));

        if (dependLibary != null) {

          setBeanValue(object, _DataObjectProperty.DependLibary, dependLibary);
        }

        Object targetRuntimeEnv = null;

        targetRuntimeEnv = resultSet.getObject(columnIndex++);

        object.setTargetRuntimeEnvNull(resultSet.getBoolean(columnIndex++));

        if (targetRuntimeEnv != null) {

          setBeanValue(object, _DataObjectProperty.TargetRuntimeEnv, targetRuntimeEnv);
        }

        Object autoDeploy = null;

        autoDeploy = resultSet.getObject(columnIndex++);

        object.setAutoDeployNull(resultSet.getBoolean(columnIndex++));

        if (autoDeploy != null) {

          setBeanValue(object, _DataObjectProperty.AutoDeploy, autoDeploy);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object lastBuildTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          lastBuildTime = resultSet.getTimestamp(columnIndex++);

        } else {
          lastBuildTime = resultSet.getObject(columnIndex++);
        }

        object.setLastBuildTimeNull(resultSet.getBoolean(columnIndex++));

        if (lastBuildTime != null) {

          setBeanValue(object, _DataObjectProperty.LastBuildTime, lastBuildTime);
        }

        Object productionType = null;

        productionType = resultSet.getObject(columnIndex++);

        object.setProductionTypeNull(resultSet.getBoolean(columnIndex++));

        if (productionType != null) {

          setBeanValue(object, _DataObjectProperty.ProductionType, productionType);
        }

        Object productionName = null;

        productionName = resultSet.getObject(columnIndex++);

        object.setProductionNameNull(resultSet.getBoolean(columnIndex++));

        if (productionName != null) {

          setBeanValue(object, _DataObjectProperty.ProductionName, productionName);
        }

        Object deployType = null;

        deployType = resultSet.getObject(columnIndex++);

        object.setDeployTypeNull(resultSet.getBoolean(columnIndex++));

        if (deployType != null) {

          setBeanValue(object, _DataObjectProperty.DeployType, deployType);
        }

        Object deployPath = null;

        deployPath = resultSet.getObject(columnIndex++);

        object.setDeployPathNull(resultSet.getBoolean(columnIndex++));

        if (deployPath != null) {

          setBeanValue(object, _DataObjectProperty.DeployPath, deployPath);
        }

        Object deployUser = null;

        deployUser = resultSet.getObject(columnIndex++);

        object.setDeployUserNull(resultSet.getBoolean(columnIndex++));

        if (deployUser != null) {

          setBeanValue(object, _DataObjectProperty.DeployUser, deployUser);
        }

        Object deployPassword = null;

        deployPassword = resultSet.getObject(columnIndex++);

        object.setDeployPasswordNull(resultSet.getBoolean(columnIndex++));

        if (deployPassword != null) {

          setBeanValue(object, _DataObjectProperty.DeployPassword, deployPassword);
        }

        Object sourceEncode = null;

        sourceEncode = resultSet.getObject(columnIndex++);

        object.setSourceEncodeNull(resultSet.getBoolean(columnIndex++));

        if (sourceEncode != null) {

          setBeanValue(object, _DataObjectProperty.SourceEncode, sourceEncode);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
